/* 
 * File:   Graph.cpp
 * Author: reinhard
 * 
 * Created on 30. September 2011, 11:26
 */

#include "Graph.h"
using namespace std;
#include <iostream>
#include <sstream>
#include <set>
#include <vector>

Graph::Graph(string fileName) {
    stringstream ss;
    stringstream st(stringstream::in | stringstream::out);
    nodes = new vector<Node*>();
    edges = new vector<Edge*>();
    ifstream myGraph;
    string buf;
    myGraph.open(fileName.c_str(), ifstream::in);
    cout << "opened Graph" << endl;
    if (myGraph.is_open()) {
        getline(myGraph, buf, '\n');
        ss << buf;
        ss >> numNodes;
    }
    for (int i = 0; i < numNodes; i++) {
        Node* newNode = new Node(i);
        nodes->push_back(newNode);
    }
    int line = 0;
    int val = -1;
    while (line < numNodes) {
        st.clear();
        getline(myGraph, buf, '\n');
        st << buf;
        for (int i = 0; i < numNodes; i++) {
            st >> val;
            if (st.fail()) cout << "FAIL!" << endl;
            if (val == 1) {
                Edge* edge = new Edge(nodes->at(line), nodes->at(i));

                edges->push_back(edge);
                nodes->at(line)->addOutEdge(edge);
                nodes->at(i) -> addInEdge(edge);
            }
        }
        line++;
    }
}

Graph::Graph(const Graph& orig) {
}

Graph::~Graph() {
}

int Graph::size() {
    return nodes->size();
}

int Graph::numOfEdges() {
    return edges->size();
}

Graph* Graph::shrinkGraph() {


}